//============================================================================
// Copyright (C) 2009-2013 Brett R. Jones 
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses 
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================

#include <string.h>
#include <RcSysPktLib/RcSysPktTypes.h>
#include <VxUtilLib/VxCommon.h>

//============================================================================
//! return true if pkt type is in range of system packets and valid length that is a multiple of 16 bytes
bool RcSysPktHdr::isValidPktLen( void )
{
    if( (0 == m_u16PktLen) ||
        (m_u16PktLen > RC_SYS_PKT_MAX_LEN) ||
        (m_u16PktLen & 0x0f) )
    {
        return false;
    }
    return true;
}

//============================================================================
//! return true if pkt type is in range of system packets and valid length that is a multiple of 16 bytes
bool RcSysPktHdr::isValidSysPkt( void )
{
    if( isValidPktLen() &&
        ((MIN_RC_SYS_PKT_TYPE <= m_u16PktType) &&
        (MAX_RC_SYS_PKT_TYPE >= m_u16PktType) ) )
    {
        return true;
    }
    return false;
}

//============================================================================
//! return true if pkt type is in range and valid length that is a multiple of 16 bytes
bool RcSysPktHdr::isValidPluginPkt( void )
{
    // plugin 0 is invalid so must be at least pkt type 0x100
    if( isValidPktLen() &&
        (( 0x100  <= m_u16PktType ) &&
        ((0x100 * eMaxPluginType) >= m_u16PktType) ) )
    {
        return true;
    }
    return false;
}

//============================================================================
//! return true if pkt type is in range and valid length that is a multiple of 16 bytes
bool RcSysPktHdr::isValidRcPkt( void )
{
    if( isValidPluginPkt() || isValidSysPkt() )
    {
        return true;
    }
    return false;
}

//============================================================================
// return true if is announce packet
bool RcSysPktHdr::IsPktAnnounce( void )
{
    return ( RC_SYS_PKT_TYPE_ANNOUNCE == m_u16PktType )?1:0;
}
